<template>
    <view class="cn-account">
        <custom><template #backText>忘记密码</template></custom>
        <navTabs :tab.sync="tab" :changeTab="key => tab.cur = key"></navTabs>
        <view class="padding-lr-30">
            <nFormItem key="form_phone" icon='cuIcon-phone' :placeholder="tab.cur == 0 ? '手机号' : '申请商家的手机号'" :data.sync="data" field="phone"></nFormItem>
            <formSendSms uri="/unloginSend" type="vcode.forgot_password" :parentData.sync="data"></formSendSms>
            <nFormItem key="form_account" v-if="tab.cur == 1" icon='cuIcon-people' placeholder="商家账号" :data.sync="data" field="account"></nFormItem>
            <nFormItem key="form_new_password_md5" icon='cuIcon-command' placeholder="新登录密码" :data.sync="data" field="new_password_md5" :password="true"></nFormItem>
            <nFormButton title="修改密码" :tap="passwordForgot"></nFormButton>
            <view class="margin-lr-30 flex justify-between text-999">
                <view @tap="$store.commit('userNavTo', '/account/login')">知道密码，去登录</view>
                <view @tap="$store.commit('userNavTo', '/account/register')">没有账号，去注册</view>
            </view>
        </view>
    </view>
</template>

<script>
    import formSendSms from '@/components/nddyny/form/sendSms.vue';
    export default {
        components: {
            formSendSms
        },
        data() {
            return {
                tab: {
                    cur: 0,
                    list: {
                        0: {
                            title: '用户忘记密码'
                        },
                        1: {
                            title: '商家忘记密码'
                        }
                    }
                },
                data: {
                    formtag: {},
                    form: {
                        phone: '',
                        sms_code: '',
                        account: '',
                        new_password_md5: ''
                    },
                }
            }
        },
        methods: {
            passwordForgot() {
                this.$api.post(this, {
                    loading: '修改密码中',
                    url: this.tab.cur == 0 ? '/account/password/updateBySmsCode' : '/seller/apply/updatePasswordByApplyUserPhone',
                    success: (Result) => {
                        if (this.$api.form.toast(this, Result)) return;
                        this.$store.commit('userToastSuccess', {
                            message: '修改成功',
                            reToUri: '/account/login'
                        });
                    }
                });
            }
        }
    }
</script>

<style lang="less">
    @import "./account.less";
</style>
